import { defineStore } from "pinia";
import api from "@/api/index";

export const useStore = defineStore("main", {
  state: () => {
    return {
      isLogin: null,
      info: null,
      storeList: null,
    };
  },
  actions: {
    async changeIsLoginAsync() {
      let bool = false;
      let { code } = await api.checkLogin();
      if (+code === 0) bool = true;
      this.isLogin = bool;
      console.log(this.isLogin);
    },
    async changeInfoAsync() {
      let { code, data } = await api.userInfo();
      if (+code === 0) {
        this.info = data;
      }
    },
    async changeStoreListAsync() {
      let { code, data } = await api.storeList();
      if (+code !== 0) data = [];
      this.storeList = data;
    },
    async removeStoreList(context) {
      if (context.storeList === null) return;
      this.changeStoreListAsync();
    },
  },
  // eslint-disable-next-line no-undef
});
